#include "header.h"

int main(int argc, char** argv) 
{
 input  params;
 char   str[80]; 
 double t = 0, dt;
 double tau_inc, tau_store = 0.;
 int    jjj = 0, jj = 0, j = 0, jj_skip; 
 FILE   *fh = fopen("temporal.dat","w");

 if (argc != 2) {
   printf("Usage: %s input.file\n", argv[0]);
   exit(1);
 } else strcpy(params.runname,argv[1]);
 fprintf(fh, "%%#1. t 2. |psi| 3. |psi|_rr 4. L 5. phase_rr 6. ss time 7. ss a 8. ss beta 9. ss beta_t\n\n");
 fclose(fh);
 read_input_parameters(&params); tau_inc = params.tau_skip; jj_skip = params.out_skip;
 init_f(&params); dt = (params.cfl)*pow(params.h, 2);

 while (params.tau < params.t_max) {
   if (tau_store < params.tau) {
     j += 1;
     /*sprintf(str,"frame%04d.png", jjj); --here
     draw_tf(str); --here*/
     if (jj < j) {
       sprintf(str,"frame%04d.txt", jjj);
       write_tf(str);
       jj += jj_skip;
       jjj += 1;
     }
     tau_store += tau_inc;
     //printf("tau = %.14e l = %.14e\tcurr dt = %e\n", params.tau, params.l, dt);
     fh = fopen("temporal.dat","a");
     find_beta(&params);
     fprintf(fh, "%.14e\t%.14e\t%.14e\t%.14e\t%.14e\t%.14e\t%.14e\t%.14e\t%.14e\n", 
              t, params.m_p, params.p_rr, params.L, 0., params.tau, 0., params.beta, 0.); 
     fclose(fh);
   }
   t += dt;
   evolve_erk6(&params);
   dt = regrid(&params);
 }

 //add_grid(&params);

 return 0;
}


